=begin pod :tag<index>

=TITLE FAQ

=SUBTITLE Frequently Asked Questions about Perl 6

=head1 General

=head2 What's the difference between Rakudo and Perl 6?

Properly speaking, L<Rakudo|http://rakudo.org/> is an implementation of Perl 6.
It's currently the most developed, but there have been other implementations in
the past and there will likely be others in the future. Perl 6 is the
definition of the language. Often, Rakudo and Perl 6 will be used
interchangeably.

=head2 Has Perl 6 been released?

Yes with the Rakudo 2015.12 implementation version on December 25th 2015.

=head2 Is there a Perl 6 version 6.0.0?

No. The first stable language specification version is v6.c ("Christmas"). Future
versions of the spec may have point releases (e.g. v6.c.2) or major releases
(e.g., v6.d).

Running C<perl6 -v> will display the language version your compiler implements:

=for code :lang<shell>
$ perl6 -v
This is Rakudo version 2017.07 built on MoarVM version 2017.07
implementing Perl 6.c.

=head2 When is v6.d going to be released?

Hopefully within a few months. Details at L<https://github.com/perl6/6.d-prep>

You can already use some of the new features by using C<use v6.d.PREVIEW>
L<pragma|https://docs.perl6.org/language/pragmas>. Also, many of the 6.d
features were already implemented in 6.c compiler, due to the lack (at the
time) of the infrastructure to support separate language versions.  Thus, when
6.d is released, you may find you were already using many of the new features.

=head2 As a Perl 6 user, what should I install?
X<|Rakudo Star (FAQ)>

Mac users can use the latest Rakudo Star DMG binary installer at
L<http://rakudo.org/downloads/star>

Windows users can use the Rakudo Star MSI binary installer. You will need
Windows Git and Strawberry Perl 5 to use zef to install library modules.

Linux users probably want to download Rakudo Star and follow the compilation
instructions at L<http://www.perl6.org/downloads/>.

There should be Linux and Mac binaries available from vendors and third
parties, although vendor versions may be outdated. Versions before
Rakudo release of 2015.12 should be avoided.

There's an official Rakudo Star docker image at
L<https://hub.docker.com/_/rakudo-star/>

=head2 As an advanced user I want to track Rakudo development.
X<|rakudobrew (FAQ)>

An option is to clone L<the repository|https://github.com/rakudo/rakudo> and
L<build from source|https://github.com/zoffixznet/r#table-of-contents>.

This will install work in progress which isn't necessarily fully functional.
To install the last official monthly release check out the tag visible at
L<https://raw.githubusercontent.com/rakudo/rakudo/master/VERSION>

Some users choose to use L<rakudobrew|https://github.com/tadzik/rakudobrew>,
which allows installation of multiple versions of rakudo. Be sure to L<read its
documentation|https://github.com/tadzik/rakudobrew#making-new-scripts-available>

In either case you will probably need to also install zef and p6doc from
the ecosystem.

=head2 Where can I find good documentation on Perl 6?

See L<the official documentation website|https://docs.perl6.org/> (especially
its L<"Language" section|https://docs.perl6.org/language.html>) as well as
the L<Resources page|https://perl6.org/resources/>.

There is a cheat sheet at
L<https://github.com/perl6/mu/raw/master/docs/Perl6/Cheatsheet/cheatsheet.txt>

Be mindful of publication dates when reading third-party articles. Anything
published before December, 2015 likely describes pre-release version of Perl 6.

You can always L<get help from a live human in our help
chat|https://webchat.freenode.net/?channels=#perl6> or L<search the chat
logs|https://www.google.com/search?q=site:irclog.perlgeek.de+inurl:perl6>.

=head2 What is the Perl 6 specification?

The specification refers to the official test suite for Perl 6. It's called
L<roast|https://github.com/perl6/roast> and is hosted on github. Any compiler
that passes the tests is deemed to implement that version of the Perl 6
specification.

Roast's "master" branch corresponds to the latest development that isn't
necessarily part of any specification yet. Other branches
correspond to specific versions; for example, "6.c-errata".

So 6.c-errata is a released language version we don't change other than to fix
errors in tests (the "errata") whereas master is the unreleased
work-in-progress that may become the next language version. Its current state
is not necessarily prescriptive of the next language version's behavior since
new additions will be reviewed for inclusion into the release.

=head2 Is there a glossary of Perl 6 related terms?

Yes, see L<glossary|/language/glossary>.

=head2 I'm a Perl 5 programmer. Where is a list of differences between Perl 5 and Perl 6?

There are several B<5to6-> guides in the L<Language section of the
documentation|https://docs.perl6.org/language.html>, most notable of which
is the L<5to6-nutshell|https://docs.perl6.org/language/5to6-nutshell> guide.

=head2 I'm a Ruby programmer looking for quickstart type docs?
X<|Ruby (FAQ)>

See the L<rb-nutshell|https://docs.perl6.org/language/rb-nutshell> guide.

=head1 Modules

=head2 Is there a CPAN (repository of third party library modules) for Perl 6?
X<|CPAN (FAQ)>X<|ecosystem>

Yes, it's the same L<CPAN|http://cpan.org/> as for Perl 5! The only difference
is when using L<PAUSE|http://pause.perl.org/> to upload the module, you'd select
C<Perl 6> as the target directory. The
L«C<App::Mi6> tool|https://modules.perl6.org/l/App::Mi6» can simplify the
uploading process. Latest versions of
L«C<zef> module installer|https://github.com/ugexe/zef»
automatically check for latest versions of a module on CPAN as well as our
L<GitHub-based ecosystem|https://github.com/perl6/ecosystem/>.

Viewing of modules available CPAN will be implemented soon on
L<modules.perl6.org website|https://modules.perl6.org/> (temporarily, it's
available as a
L<raw JSON file|https://github.com/ugexe/Perl6-ecosystems/blob/master/cpan.json>

=head2 Is there a perldoc (command line documentation viewer) for Perl 6?
X<|p6doc (FAQ)>

Yes, it's called p6doc and is present in the ecosystem under that name. It's
present in Rakudo Star but you will need to install it using the monthly
release.

=head2 Can I use Perl 5 modules from Perl 6?
X<|Perl 5 modules (FAQ)>

Yes, with L<Inline::Perl5|https://github.com/niner/Inline-Perl5/>, which works
well with most Perl 5 modules. It can even run Perl 5 Catalyst and DBI.

=head2 Can I use C and C++ from Perl 6?
X<|C and C++ (FAQ)>

L<Nativecall|https://docs.perl6.org/language/nativecall> makes this
particularly easy.

=head2 Nativecall can't find libfoo.so and I only have libfoo.so.1.2!

This is commonly seen on Debian-like systems. You need to install C<libfoo-dev>
package, to set a sym link for the missing file.

=head2 Where have all the traditional UNIX library functions gone?
X<|UNIX library functions (FAQ)>
X<|POSIX (FAQ)>

It's very easy to use Nativecall to access them.

An ecosystem module L<POSIX|https://github.com/cspencer/perl6-posix> is
also available.

=head2 Does Rakudo have a core standard library?

L<Rakudo Star distribution|https://rakudo.perl6.org/downloads/star/> does come
with L<many useful modules|https://github.com/rakudo/star/tree/master/modules>.

Rakudo compiler-only release includes L<only a couple of the most
basic modules|https://docs.perl6.org/language/modules-core>.

Many more modules can be found in the L<ecosystem|http://modules.perl6.org/>.

=head2 Is there something like C<B::Deparse>/How can I get hold of the AST?

Use C<--target=optimize> command line option to view the AST of your program,
e.g., C<perl6 --target=optimize -e 'say "hi"'>

The target C<optimize> gives the AST after the static optimizer did its job,
while target C<ast> gives the AST before that step. To get the full list of
available targets, run C<perl6 --stagestats -e "">

=head2 What is Precompilation?
X<|Precompile (FAQ)>

When you load a module for the first time, Rakudo compiles it into bytecode,
and both stores it on disk, and uses the compiled bytecode. On subsequent
loads, Rakudo prefers to load the bytecode, because that tends to be
significantly faster.

=head1 Language Features

=head2 How can I dump Perl 6 data structures
(like Perl 5 Data::Dumper and similar)?
X<|Data::Dumper (FAQ)>

Typical options are to use L<say> routine that uses L<gist> method that
gives the "gist" of the object being dumped. More detailed output can be
obtained by calling L<perl> method that typically returns representation
in L<EVAL|/routine/EVAL>-able code.

If you're using the L<rakudo|http://rakudo.org> implementation, you can use
the L«rakudo-specific C<dd> routine|/programs/01-debugging#Dumper_function_dd»
for dumping, whose output is similar to L<.perl>, but with more information.

Examples:

=begin code :ok-test<dd>
    my $foo = %( foo => 'bar' );
    say $foo.perl;   # OUTPUT: «${:foo("bar")}␤»
    say $foo;        # OUTPUT: «{foo => bar}␤»

    # non-standard routine available in rakudo implementation:
    dd $foo;         # OUTPUT: «Hash $foo = ${:foo("bar")}␤»
=end code

There are also L<several ecosystem modules|https://modules.perl6.org/s/dump>
that provide more control over how data structures are dumped, including support
for colored output in.

=head2 How can I get command line history in the Perl 6 prompt (REPL)?

Install  L<Linenoise|https://github.com/hoelzro/p6-linenoise/> from the
ecosystem.

An alternative for UNIX-like systems is to install C<rlwrap>. This can
be done on Debian-ish systems by running:

=for code :lang<shell>
sudo apt-get install rlwrap

=head2 Why is the Rakudo compiler so apologetic?

If SORRY! is present in the output the error is a compile time error
otherwise it's runtime.

Example:

=for code
    say 1/0;   # Attempt to divide 1 by zero using div

=begin code :skip-test<compile time error>
    sub foo( Int $a, Int $b ) {...}
    foo(1)     # ===SORRY!=== Error while compiling ...
=end code

=head2 What is C<(Any)>?

L«C<Any>|/type/Any» is a top level class most objects inherit from.
The C<Any> type object is
L<the default value|/type/Attribute.html#Trait_is_default> on variables and
parameters without an explicit type constraint, which means you'll
likely see C<(Any)> printed when you output a L<gist|/routine/gist> of
a variable without any value, such as using L«C<say> routine|/routine/say»:

=begin code
my $foo;
say $foo; # OUTPUT: «(Any)␤»

my Int $baz;
say $baz; # OUTPUT: «(Int)␤»

my $bar = 70;
say $bar; # OUTPUT: «70␤»
=end code

To test whether a variable has any defined values, see
L<DEFINITE|/classtut#index-entry-DEFINITE> and L<defined>
routines. Several other constructs exist that test for definiteness, such as
L«C<with>, C<orwith>, and C<without>|/syntax/with%20orwith%20without»
statements, L«C<//>|/routine/$SOLIDUS$SOLIDUS», L<andthen>, L<notandthen>, and
L<orelse> operators, as well as L<type constraint smileys|/type/Signature#Constraining_Defined_and_Undefined_Values>.

=head2 What is C<so>?

C<so> is a loose precedence operator that coerces to L<Bool|/type/Bool>.

It has the same semantics as the C<?> prefix operator, just like
C<and> is the low-precedence version of C<&&>.

Example usage:

    say so 1|2 == 2;    # OUTPUT: «True␤»

In this example, the result of the comparison (which is a
L<Junction|/type/Junction>), is converted to Bool before being printed.

=head2 What are those C<:D> and C<:U> things in signatures?

In Perl 6, classes and other types are objects and pass type checks
of their own type.

For example, if you declare a variable

    my Int $x = 42;

then not only can you assign integers (that is, instances of class Int) to it,
but the C<Int> type object itself:

    =begin code :preamble<my Int $x>
    $x = Int
    =end code

If you want to exclude type objects, you can append the C<:D> type smiley,
which stands for "definite":

    =begin code
    my Int:D $x = 42;
    $x = Int;

    # dies with:
    # Type check failed in assignment to $x;
    # expected Int:D but got Int
    =end code

Likewise, C<:U> constrains to undefined values, that is, type objects.

To explicitly allow either type objects or instances, you can use C<:_>.

=head2 What is the C«-->» thing in the signature?

L«-->|/type/Signature#Constraining_Return_Types» is a return constraint, either
a type or a definite value.

Example of a type constraint:

    sub divide-to-int( Int $a, Int $b --> Int ) {
            return ($a / $b).narrow;
    }

    divide-to-int(3, 2)
    # Type check failed for return value; expected Int but got Rat

Example of a definite return value:

    sub discard-random-number( --> 42 ) { rand }
    say discard-random-number;
    # OUTPUT: «42␤»

In this case, the final value is thrown away because the return value is already specified.

=head2 How can I extract the values from a Junction?
X<|Junction (FAQ)>

If you want to extract the values (eigenstates) from a
L<Junction|/type/Junction>, you are probably doing something wrong and
should be using a L<Set|/type/Set> instead.

Junctions are meant as matchers, not for doing algebra with them.

If you want to do it anyway, you can abuse autothreading for that:

    sub eigenstates(Mu $j) {
        my @states;
        -> Any $s { @states.push: $s }.($j);
        @states;
    }

    say eigenstates(1|2|3).join(', ');
    # prints 1, 2, 3 or a permutation thereof

=head2 If Str is immutable, how does C<s///> work? If Int is immutable,
how does C<$i++> work?

In Perl 6, values of many basic types are immutable, but the variables holding
them are not. The C<s///> operator works on a variable, into which it puts a
newly created string object. Likewise, C<$i++> works on the C<$i> variable, not
just on the value in it.

Knowing this, you would not try to change a literal string (e.g. like
C<'hello' ~~ s/h/H/;>), but you might accidentally do something equivalent
using C<map> as follows.

    my @foo = <hello world>.map: { s/h/H/ };

    # dies with
    # Cannot modify an immutable Str (hello)

    my @bar = <hello world>».subst-mutate: 'h', 'H';

    # dies with
    # Cannot resolve caller subst-mutate(Str: Str, Str);
    # the following candidates match the type but require
    # mutable arguments: ...

Instead of modifying the original value in place, use a routine or operator
that returns a new value:

    my @foo = <hello world>.map: { S/h/H/ };  # ['Hello','world']
    my @bar = <hello world>».subst: 'h', 'H'; # ['Hello','world']

See the documentation on L<containers|/language/containers> for more
information.

=head2 What's up with array references and automatic dereferencing?
Do I need the C<@> sigil?

In Perl 6, nearly everything is a reference, so talking about taking
references doesn't make much sense. Scalar variables can also contain
arrays directly:

    my @a = 1, 2, 3;
    say @a;                 # OUTPUT: «[1 2 3]␤»
    say @a.^name;           # OUTPUT: «Array␤»

    my $scalar = @a;
    say $scalar;            # OUTPUT: «[1 2 3]␤»
    say $scalar.^name;      # OUTPUT: «Array␤»

The big difference is that arrays inside a scalar act as one value in list
context, whereas arrays will be happily iterated over.

    my @a = 1, 2, 3;
    my $s = @a;

    for @a { ... }          # loop body executed 3 times
    for $s { ... }          # loop body executed only once

    my @flat = flat @a, @a;
    say @flat.elems;            # OUTPUT: «6␤»

    my @nested = flat $s, $s;
    say @nested.elems;          # OUTPUT: «2␤»

You can force flattening with C<@( ... )> or by calling the C<.list> method
on an expression, and item context (not flattening) with C<$( ... )>
or by calling the C<.item> method on an expression.


=head2 Why sigils? Couldn't you do without them?
X<|sigils (FAQ)>

There are several reasons:

=item they make it easy to interpolate variables into strings

=item they form micro-namespaces for different variables and twigils, thus avoiding name clashes

=item they allow easy single/plural distinction

=item they work like natural languages that use mandatory noun markers, so our brains are built to handle it

=item they aren't mandatory, since you can declare sigilless names (if you don't mind the ambiguity)

=head2 "Type Str does not support associative indexing."

You likely tried to mix string interpolation and key characters, like HTML tags:

    my $foo = "abc";
    say "$foo<html-tag>";

Perl 6 thinks C<$foo> to be a Hash and C«<html-tag>» to be a string literal
hash key. Use a closure to help it to understand you.

    my $foo = "abc";
    say "{$foo}<html-tag>";

=head2 Does Perl 6 have coroutines? What about C<yield>?
X<|coroutine (FAQ)>

Perl 6 has no C<yield> statement like Python does, but it does offer similar
functionality through lazy lists. There are two popular ways to write
routines that return lazy lists:

    =begin code :preamble<sub have_data {};sub some_data {};>
    # first method, gather/take
    my @values = gather while have_data() {
        # do some computations
        take some_data();
        # do more computations
    }

    # second method, use .map or similar method
    # on a lazy list
    my @squares = (1..*).map(-> \x { x² });
    =end code

=head2 Why can't I initialize private attributes from the new method,
and how can I fix this?

Code like

    class A {
        has $!x;
        method show-x {
            say $!x;
        }
    }
    A.new(x => 5).show-x;

does not print 5. Private attributes are I<private>, which means invisible to
the outside. If the default constructor could initialize them, they would leak
into the public API.

If you still want it to work, you can add a C<submethod BUILD> that
initializes them:

    class B {
        has $!x;
        submethod BUILD(:$!x) { }
        method show-x {
            say $!x;
        }
    }
    B.new(x => 5).show-x;

C<BUILD> is called by the default constructor (indirectly, see
L<Object Construction|/language/objects#Object_Construction>
for more details) with all the named arguments that the user passes to the
constructor. C<:$!x> is a named parameter with name C<x>, and when called
with a named argument of name C<x>, its value is bound to the attribute C<$!x>.

But don't do that. If the name is public, there is no downside to
declaring it that way with C<$.x> since the external view is readonly
by default, and you can still access it internally with C<$!x>.

=head2 How and why do C<say>, C<put> and C<print> differ?

The most obvious difference is that C<say> and C<put> append
a newline at the end of the output, and C<print> does not.

But there's another difference: C<print> and C<put> converts its
arguments to a string by calling the C<Str> method on each item
passed to, C<say> uses the C<gist> method instead.  The C<gist> method,
which you can also create for your own classes, is intended to create a
C<Str> for human interpretation.  So it is free to leave out information
about the object deemed unimportant to understand the essence of the object.

Or phrased differently, C<$obj.Str> gives a string representation,
C<$obj.gist> a short summary of that object suitable for fast recognition
by a human, and C<$obj.perl> gives a Perlish representation from which the
object could be re-created.

Example: type objects, also known as "undefined values", stringify
to an empty string and warn, whereas the C<gist> method returns the name
of the type between parentheses (to indicate there's nothing in that value
except the type).

    my Date $x;     # $x now contains the Date type object
    print $x;       # empty string plus warning
    say $x;         # OUTPUT: «(Date)␤»

If you like to show a debugging version of an object, it is probably better
to use the L«rakudo-specific C<dd> routine|/programs/01-debugging#Dumper_function_dd».
It essentially does a C<$obj.perl> and shows that on STDERR rather than STDOUT,
so it won't interfere with any "normal" output of your program.

So, C<say> is optimized for casual human interpretation, C<dd> is optimized
for casual debugging output and C<print> and C<put> are more generally suitable
for producing output.

C<put> is thus a hybrid of C<print> and C<say>; like C<print>, it calls the
C<Str> method on the object.  And like C<say>, it adds a newline at the end
of the output.

=head2 What's the difference between C<token> and C<rule> ?

C<regex>, C<token> and C<rule> introduce regexes, but with
slightly different semantics.

C<token> implies the C<:ratchet> or C<:r> modifier, which prevents the
rule from backtracking.

C<rule> implies both the C<:ratchet> and C<:sigspace> (short C<:s>)
modifier, which means a rule doesn't backtrace, and it treats
whitespace in the text of the regex as C«<.ws>» calls (i.e.,
matches whitespace, which is optional except between two word
characters). Whitespace at the start of the regex and at the start
of each branch of an alternation is ignored.

C<regex> declares a plain regex without any implied modifiers.

=head2 What's the difference between C<die> and C<fail>?

C<die> throws an exception.

C<fail> returns a C<Failure> object.  (If the caller has declared C<use fatal;>
in the calling lexical scope, C<fail> throws an exception instead of returning.)

A C<Failure> is an "unthrown" or "lazy" exception. It's an object that contains
the exception, and throws the exception if you try to use the C<Failure>
as an ordinary object, or ignore it in sink context.

A C<Failure> returns C<False> from a C<defined> check, and you can extract
the exception with the C<exception> method.

=head2 Why is C<wantarray> or C<want> gone?
Can I return different things in different contexts?

Perl 5 has the L<C<wantarray>|/language/5to6-perlfunc#wantarray> function that
tells you whether it's called in void, scalar or list context. Perl 6 has no
equivalent construct because context does not flow inwards; i.e.,
a routine would need time travel to know which context it's called in because
context is lazy (known only when the results are used later).

For example, Perl 6 has multiple dispatch. So, in a code example like

    =begin code :preamble<sub f {}>
    multi w(Int $x) { say 'Int' }
    multi w(Str $x) { say 'Str' }
    w(f());
    =end code

there's no way to determine if the caller of sub C<f> wants a string or
an integer, because it's not yet known what the caller is. In general
this requires solving the halting problem, which even Perl 6 compiler
writers have trouble with.

One way to achieve context sensitivity in Perl 6 is to return an object
that knows how to respond to method calls that are typical for a context.
In Perl 6, this is actually a L<lot easier|/language/5to6-perlfunc#wantarray>
than it may sound, and other features of the language either mitigate the
need to do so in the first place or make it possible to cover most of the
use cases of wantarray.

For example, regex matches return L<Match objects that know how to respond
to list indexing, hash indexing, and that can turn into the matched
string|/type/Match>.

=head2 What's the difference between C<Pointer> and C<OpaquePointer>?

C<OpaquePointer> is deprecated and has been replaced with C<Pointer>.

=head1 Perl 6 Implementation
X<|Perl 6 Implementation (FAQ)>

=head2 What Perl 6 Implementations are available?

Currently the best developed is Rakudo (using multiple Virtual Machine
backends). Historic implementations include Niecza (.NET) and Pugs (Haskell).
Others are listed at  L<Perl 6 Compilers|https://www.perl6.org/compilers/>

=head2 What language is Rakudo written in?

A short answer is that Rakudo is written almost entirely in Perl 6. A more
detailed answer is that Rakudo is written in a mixture of Perl 6 and NQP ("Not
Quite Perl"). NQP is a lightweight Perl 6-like environment for virtual
machines; it's designed to be a high-level way to create compilers and
libraries for virtual machines (such as MoarVM and JVM) using Perl 6 syntax.

=head2 What language is NQP written in?
X<|NQP (FAQ)>

NQP is a mixture of (1) NQP code, (2) whatever language the underlying virtual
machine is using, (3) some third-party C and Java libraries, and (4) some
bootstrapping files created by earlier runs of the build process.

=head2 Is Perl 6 Lisp?

    (not (not Nil))

=head1 Meta Questions and Advocacy

=head2 Why is Perl 6 called Perl?

… As opposed to some other name that didn't imply all the things
that the higher number might indicate on other languages.

The short answer is that it was Larry's choice under
L<Rule 1|http://perldoc.perl.org/5.12.4/perlhack.html#DESCRIPTION>.

The community considers Perl 5 and Perl 6 sister languages - they have
a lot in common, address many of the same problem spaces, but Perl 6 is not
intended to replace Perl 5. In fact, both languages interoperate with
each other.

=head2 When will Perl 6 be ready? Is it ready now?

Readiness of programming languages and their compilers is not a binary
decision. As the language and the implementations evolve, they
grow steadily more usable. Depending on your needs,
Perl 6 and its compilers may or may not be ready for you.

That said, version 6.c (Christmas 2015) is the first official release of Perl 6
as a language, along with a validation suite and a compiler that passes it.

=head2 Why should I learn Perl 6? What's so great about it?

Perl 6 unifies many great ideas that aren't usually found in other programming
languages. While several other languages offer some of these features, none of
them offer all.

=item Perl 6 offers procedural, object-oriented AND functional programming methodologies.

=item Easy to use consistent syntax, using invariable sigils for data-structures.

=item Full grapheme based Unicode support, including Annex #29.

=item Clean, more readable regular expressions; taken to the next level of usability, with a lot more functionality. Named regular expressions improve ease of use.

=item Junctions allowing easy checking of multiple possibilities; e.g., $a == 1|3|42 ( is $a equal to 1 or 3 or 42).

=item Dynamic variables provide a lexically scoped alternative to global variables.

=item Emphasis on composability and lexical scoping to prevent “action at a distance”; e.g., imports are always lexically scoped.

=item Easy to understand consistent scoping rules and closures.

=item Powerful object orientation, with classes and roles (everything can be seen as an object). Inheritance. Subtyping. Code-reuse.

=item Introspection into objects and meta-objects (turtles all the way down).

=item Meta Object Protocol allowing for meta-programming without needing to generate / parse code.

=item Subroutine and method signatures for easy unpacking of positional and named parameters.

=item Multi dispatch for identically named subroutines/methods with different signatures, based on arity, types and optional additional code.

=item Compile time error reporting on unknown subroutines / impossible dispatch.

=item Optional gradual type-checking at no additional runtime cost. With optional type annotations.

=item Advanced error reporting based on introspection of the compiler/runtime state. This means more useful, more precise error messages.

=item Phasers (like BEGIN / END) allow code to be executed at scope entry / exit, loop first / last / next and many more special contexts.

=item High level concurrency model, both for implicit as well as explicit multi-processing, which goes way beyond primitive threads and locks. Perl 6's concurrency offers a rich set of (composable) tools.

=item Multiple-core computers are getting used more and more, and with Perl 6 these can be used thanks to parallelism, both implicit (e.g., with the >>. method) and explicit ( start { code } ). This is important, because Moore's Law is ending.

=item Structured language support is provided to enable programming for asynchronous execution of code.

=item Supplies allow code to be executed when something happens (like a timer, or a signal, or a file-system event).

=item react / whenever / supply keywords allows easy construction of interactive, event driven applications.

=item Lazy evaluation when possible, eager evaluation when wanted or necessary. This means, for example, lazy lists, and even infinite lazy lists, like the Fibonacci sequence, or all prime numbers.

=item Native data types for faster, closer to the metal, processing.

=item Interfacing to external libraries in C / C++ are trivially simple with NativeCall.

=item Interfacing with Perl 5 (CPAN) / Python modules trivially simple with Inline::Perl5 and Inline::Python.

=item Can have multiple versions of a module installed and loaded simultaneously.

=item System administration simplified due to simpler update/upgrade policies.

=item Simple numeric computation without precision loss because of Rats (rational numbers).

=item Extensible grammars for parsing data or code (which Perl 6 uses to parse itself).

=item Perl 6 is a very mutable language (define your own functions, operators, traits and data-types, which modify the parser for you).

=item Large selection of data-types, plus the possibility to create your own types.

=item Multi-dimensional shaped and/or native arrays with proper bounds checking.

=item Execute code at any time during parsing of a grammar, or when a certain match occurred.

=item Adding a custom operator or adding a trait is as simple as writing a subroutine.

=item Automatic generation of hyper-operators on any operator (system or custom added).

=item Runs on a variety of back-ends. Currently MoarVM & JVM, JavaScript in development, more may follow.

=item Runtime optimization of hot code paths during execution (JIT).

=item Runs on small (e.g., Raspberry Pi) and large multi-processor hardware.

=item Garbage collection based: no timely destruction, so no ref-counting necessary. Use phasers for timely actions.

=item Methods can be mixed into any instantiated object at runtime; e.g., to allow adding out-of-band data.

=item Easy command-line interface accessible by MAIN subroutine with multiple dispatch and automated usage message generation.

=item Fewer lines of code allow for more compact program creation. Huffman-coding of names allows for better readability.

=item Lazy lists defined with a simple iterator interface, which any class can supply by minimally supplying a single method.

=item Perl 6's mottos remain the same as they have been for Perl all along: “Perl is different. In a nutshell, Perl is designed to make the easy jobs easy, without making the hard jobs impossible.” and “There Is More Than One Way To Do It”. Now with even more -Ofun added.

Please see the
L<feature comparison matrix|https://perl6.org/compilers/features>
for an overview of implemented features.

=head2 Is Perl 6 fast enough for me?

That depends on what you are doing. Rakudo has been developed with the
philosophy of "make it work right then make it work fast". It's fast for some
things already but needs work for others. Since Perl 6 provides lots of clues
to the JIT that other dynamic languages don't, we think we'll have a lot of
headroom for performance improvements.

The following crude benchmarks, with all the usual caveats about such things,
show that Perl 6 can be faster than Perl 5 for similar tasks if
the big weaponry is included; at the same time, Perl 5 can be faster
if only the bare bones are included. Similar situation can be observed
when comparing Perl 6 to other languages.

Try it on your system. You may be pleasantly surprised!

Examples:

    =begin code
    # Perl 6 version
    use v6.c;

    class Foo { has $.i is rw };

    for 1..1_000_000 -> $i {
        my $obj = Foo.new;
        $obj.i = $i;
    }
    =end code

    =begin code :lang<perl5>
    # Perl 5 version
    package Foo;
    use Moose;

    has i => (is => 'rw');

    __PACKAGE__->meta->make_immutable;

    for my $i (1..1_000_000) {
        my $obj = Foo->new;
        $obj->i($i);
    }

    1;

    # Another Perl 5 version that offers bare-bones set of features
    # compared to Moose/Perl 6's version but those are not needed in this
    # specific, simple program anyway.
    package Foo;
    use Mojo::Base -base;

    has 'i';

    for my $i (1..1_000_000) {
        my $obj = Foo->new;
        $obj->i($i);
    }

    1;
    =end code

    =begin code
    # A perl program which works under both perl5 (with perl -Mbigint)
    # and perl6

    my ($prev, $current) = (1, 0);

    for (0..100_000) {
        ($prev, $current) = ($current, $prev + $current);
    }
    print $current;
    =end code

=end pod

# vim: expandtab softtabstop=4 shiftwidth=4 ft=perl6
